import React from 'react';
import { inject, observer } from 'mobx-react';
import { Modal, message, Button, Tag,Spin } from "antd";

import { WeaLocaleProvider, WeaTop, WeaRightMenu, WeaTab, WeaReqTop, WeaDialog, WeaTag,WeaAlertPage} from 'ecCom';
import { WeaTableNew } from "comsMobx";
import {Condition} from '../list/listCondition';
import {Text} from '../util/text';
const text = new Text();

const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@inject("infoCountStore")
@observer
class InfoCount extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
        }
    }

    componentDidMount() {
        const {infoCountStore} = this.props;
        infoCountStore.getInfoCountCondition();
    }

    componentWillReceiveProps(nextProps) {
        const {infoCountStore} = this.props;
        if (this.props.location.key !== nextProps.location.key) {
            infoCountStore.getInfoCountCondition();
        }
    }

    getTopButtons = () => {
        const {infoCountStore} = this.props;
        let btns = [];
        btns.push(
            infoCountStore.getTopButton()
        )
        return btns;
    }

    handleChange(data) {
        const {infoCountStore} = this.props;
        let key = Object.keys(data)[0]
        if (key == "type") {
            if(data[key].value == '0' || data[key].value == '1') {
                infoCountStore.form.updateFields({title:'政务信息积分表'});
            }
            if(data[key].value == '2') {
                infoCountStore.form.updateFields({title:'奖惩信息'});
            }
            
        }
    }

    getHtml = () => {
        const {infoCountStore} = this.props;
        const {htmlJson,status:{isShowDetail}} = infoCountStore;
        // let html = [];
        // if (htmlJson && htmlJson.dateRange != '') {
        //     html.push(<h1> {htmlJson.dateRange}{htmlJson.title} </h1>);
        // } else {
        //     html.push(<h1> {htmlJson.title} </h1>);
        // }
        // htmlJson && htmlJson.list && htmlJson.list.map(m => {
        //     html.push(<p><b>{m.reportOrgName}({m.count}条共计{m.sumScore}分) </b></p>);
        //     if (infoCountStore.type == '0' || infoCountStore.type == '1') {
        //         m.infoSiftList && m.infoSiftList.map((n, i) => {
        //             let index = i + 1;
        //             html.push(<span>
        //                 {index + "." + n.infoSiftTitle + "     (" + n.journalTitle + "  " + n.column + "  " + n.score + "分)"}
        //             </span>);
        //             html.push(<br />);
        //         })
        //     }
        //     if (infoCountStore.type == '2') {
        //         m.infoAdjustList && m.infoAdjustList.map((n, i) => {
        //             let index = i + 1;
        //             let score = "";
        //             if(n.adjustType == '0') {
        //                 score = "+" + n.adjustScore;
        //             } else {
        //                 score = "-" + n.adjustScore;
        //             }
        //             html.push(<span>
        //                 {index + "." + n.adjustReason + "     (" + score + "分)"}
        //             </span>);
        //             html.push(<br />);
        //         })
        //     }

        // })

        let html = '';
        if (htmlJson && htmlJson.dateRange != '') {
            html += "<h1>";
            html += htmlJson.dateRange;
            html += htmlJson.title;
            html += "</h1>";
        } else {
            html += "<h1>";
            html += htmlJson.title;
            html += "</h1>";
        }
        htmlJson && htmlJson.list && htmlJson.list.map(m => {
            let content = "<p><b>" + m.reportOrgName + "(" + m.count + text.STRIP + text.TOTAL + m.sumScore + text.SCORE +")</b></p>"
            html += content;
            if (infoCountStore.type == '0' || infoCountStore.type == '1') {
                m.infoSiftList && m.infoSiftList.map((n, i) => {
                    let index = i + 1;
                    html += "<span>";
                    if(isShowDetail == '1') {       //信息积分表展示得分明细
                        html = html + index + "." + n.infoSiftTitle + "    (" + n.journalTitle + "  " + n.column + "  " + n.score + text.SCORE + ")";
                    } else {
                        html = html + index + "." + n.infoSiftTitle;
                    }
                    html += "</span><br />"
                })
            }
            if (infoCountStore.type == '2') {
                m.infoAdjustList && m.infoAdjustList.map((n, i) => {
                    let index = i + 1;
                    let score = "";
                    if(n.adjustType == '0') {
                        score = "+" + n.adjustScore;
                    } else {
                        score = "-" + n.adjustScore;
                    }
                    html += "<span>";
                    if(isShowDetail == '1') {
                        html = html + index + "." + n.adjustReason + "    (" + score + text.SCORE + ")";
                    } else {
                        html = html + index + "." + n.adjustReason;
                    }
                    html += "</span><br />";
                })
            }

        })

        return html;
    }

    render() {
        const { infoCountStore} = this.props;
        const {loadingSpin, isRight,title, status: {loading}, setState, form, condition, htmlJson,previewFlag} = infoCountStore;
        const rightMenu = infoCountStore.getRightMenu();
        if (loadingSpin) {
            return <div className="h100" style={{ textAlign: 'center', paddingTop: '300px' }}><Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@rcjt41`} size="large"/></div>
        }
        if (!isRight) {
            return <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@fpz7fd`}><div>{getLabel(382663, '暂无权限') }</div></WeaAlertPage>
        }
        return (
            <div>
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@5qvups`}
                    datas={rightMenu}>

                    <div>
                        <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@dgpxwm`}
                            title={title}
                            icon={<i className='icon-coms-government' />}
                            iconBgcolor='#f14a2d'
                            loading={loading}
                            buttons={this.getTopButtons() }
                            showDropIcon={true}
                            dropMenuDatas={rightMenu}
                            >
                            <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@cnv942`}  form={form} condition={condition} handleChange={this.handleChange.bind(this) }></Condition>
                            <div class="wea_govern_info_html">
                                {previewFlag && <div dangerouslySetInnerHTML={{ __html: this.getHtml() }}></div> }
                            </div>
                        </WeaTop>
                    </div>
                </WeaRightMenu>
            </div>
        )
    }

}

export default InfoCount;